package br.uff.es2.xadrez.core;

public class Knight extends Piece {

    public Knight(Color color, String imageFilePath) {
        this.color = color;
        this.imageFilePath = imageFilePath;
        this.moved = false;
        this.value = 3;
    }

    @Override
    public int[][] getAvaiableMoves(int[] posicao, Piece[][] board) {
        int[][] availableMoves = new int[8][8];
        if (posicao[0]+1 < 8) {
            if (posicao[1]+2 < 8) {
                if (board[posicao[0]+1][posicao[1]+2] == null) {
                    availableMoves[posicao[0]+1][posicao[1]+2] = 1;
                } else {
                    if (board[posicao[0]+1][posicao[1]+2].getColor() != getColor()) {
                        availableMoves[posicao[0]+1][posicao[1]+2] = 1;
                    }
                }
            }
            if (posicao[1]-2 >= 0) {
                if (board[posicao[0]+1][posicao[1]-2] == null) {
                    availableMoves[posicao[0]+1][posicao[1]-2] = 1;
                } else {
                    if (board[posicao[0]+1][posicao[1]-2].getColor() != getColor()) {
                        availableMoves[posicao[0]+1][posicao[1]-2] = 1;
                    }
                }
            }
        }
        if (posicao[0]-1 >= 0) {
            if (posicao[1]+2 < 8) {
                if (board[posicao[0]-1][posicao[1]+2] == null) {
                    availableMoves[posicao[0]-1][posicao[1]+2] = 1;
                } else {
                    if (board[posicao[0]-1][posicao[1]+2].getColor() != getColor()) {
                        availableMoves[posicao[0]-1][posicao[1]+2] = 1;
                    }
                }
            }
            if (posicao[1]-2 >= 0) {
                if (board[posicao[0]-1][posicao[1]-2] == null) {
                    availableMoves[posicao[0]-1][posicao[1]-2] = 1;
                } else {
                    if (board[posicao[0]-1][posicao[1]-2].getColor() != getColor()) {
                        availableMoves[posicao[0]-1][posicao[1]-2] = 1;
                    }
                }
            }
        }
        if (posicao[0]+2 < 8) {
            if (posicao[1]+1 < 8) {
                if (board[posicao[0]+2][posicao[1]+1] == null) {
                    availableMoves[posicao[0]+2][posicao[1]+1] = 1;
                } else {
                    if (board[posicao[0]+2][posicao[1]+1].getColor() != getColor()) {
                        availableMoves[posicao[0]+2][posicao[1]+1] = 1;
                    }
                }
            }
            if (posicao[1]-1 >= 0) {
                if (board[posicao[0]+2][posicao[1]-1] == null) {
                    availableMoves[posicao[0]+2][posicao[1]-1] = 1;
                } else {
                    if (board[posicao[0]+2][posicao[1]-1].getColor() != getColor()) {
                        availableMoves[posicao[0]+2][posicao[1]-1] = 1;
                    }
                }
            }
        }
        if (posicao[0]-2 >= 0) {
            if (posicao[1]+1 < 8) {
                if (board[posicao[0]-2][posicao[1]+1] == null) {
                    availableMoves[posicao[0]-2][posicao[1]+1] = 1;
                } else {
                    if (board[posicao[0]-2][posicao[1]+1].getColor() != getColor()) {
                        availableMoves[posicao[0]-2][posicao[1]+1] = 1;
                    }
                }
            }
            if (posicao[1]-1 >= 0) {
                if (board[posicao[0]-2][posicao[1]-1] == null) {
                    availableMoves[posicao[0]-2][posicao[1]-1] = 1;
                } else {
                    if (board[posicao[0]-2][posicao[1]-1].getColor() != getColor()) {
                        availableMoves[posicao[0]-2][posicao[1]-1] = 1;
                    }
                }
            }
        }
        return availableMoves;
    }
}
